//
//  SpeechSynthesisViewController.m
//  ios7Sample
//
//  Created by GeIL on 16/7/13.
//  Copyright © 2016年 KS. All rights reserved.
//

#import "SpeechSynthesisViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface SpeechSynthesisViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textField;

@property (nonatomic, strong) AVSpeechSynthesizer *synthesizer;

@end

@implementation SpeechSynthesisViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.

    self.synthesizer = [[AVSpeechSynthesizer alloc]init];
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if ([self.textField canBecomeFirstResponder]) {
        [self.textField resignFirstResponder];
    }
    [super touchesBegan:touches withEvent:event];
}

#pragma mark say Void
- (IBAction)say:(UIButton *)sender {
    
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:self.textField.text];
    [self.synthesizer speakUtterance:utterance];
    
}

@end
